<html>
<head><meta charset="utf-8"><title>pthread_cancel looks unsound · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html">pthread_cancel looks unsound</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178203749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178203749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178203749">(Oct 15 2019 at 15:22)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=aa730479e323f7efe10c4d5acd590190" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=aa730479e323f7efe10c4d5acd590190">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=aa730479e323f7efe10c4d5acd590190</a></p>



<a name="178203779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178203779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178203779">(Oct 15 2019 at 15:23)</a>:</h4>
<p>notice how the destructor of DropGuard is never called</p>



<a name="178203788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178203788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178203788">(Oct 15 2019 at 15:23)</a>:</h4>
<p>Yet the DropGuard variable is deallocated</p>



<a name="178203934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178203934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178203934">(Oct 15 2019 at 15:24)</a>:</h4>
<p>We do guarantee that destructors of variables are called before they are deallocated (required for Pin being sound)</p>



<a name="178205654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178205654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178205654">(Oct 15 2019 at 15:42)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I recall an issue about this somewhere but I can't find it</p>



<a name="178205722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178205722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178205722">(Oct 15 2019 at 15:43)</a>:</h4>
<p>I also recall that actually something like this should cause the other thread to unwind from a cancellation point</p>



<a name="178205975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178205975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178205975">(Oct 15 2019 at 15:45)</a>:</h4>
<p>Good thing it's unsafe then ;)</p>



<a name="178206134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178206134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178206134">(Oct 15 2019 at 15:47)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=release&amp;edition=2018&amp;gist=596dc7790e74de1da07fbbceb29e7854" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=release&amp;edition=2018&amp;gist=596dc7790e74de1da07fbbceb29e7854">https://play.rust-lang.org/?version=nightly&amp;mode=release&amp;edition=2018&amp;gist=596dc7790e74de1da07fbbceb29e7854</a></p>



<a name="178206164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178206164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178206164">(Oct 15 2019 at 15:47)</a>:</h4>
<p>It sometimes unwinds, and sometimes just gets deallocated without unwinding</p>



<a name="178206337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178206337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178206337">(Oct 15 2019 at 15:49)</a>:</h4>
<p>it depends on whether I run it in debug or release</p>



<a name="178206415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178206415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178206415">(Oct 15 2019 at 15:50)</a>:</h4>
<p>and the timings</p>



<a name="178206657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178206657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178206657">(Oct 15 2019 at 15:53)</a>:</h4>
<p>So I kind of expected that this would unwind</p>



<a name="178206670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178206670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178206670">(Oct 15 2019 at 15:53)</a>:</h4>
<p>That's bad in another whole dimension (all the syscalls or libc APIs are <code>nounwind</code>)</p>



<a name="178206694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178206694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178206694">(Oct 15 2019 at 15:53)</a>:</h4>
<p>But what I did not expect is that this would also terminate the thread without unwinding</p>



<a name="178206764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178206764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178206764">(Oct 15 2019 at 15:54)</a>:</h4>
<p>I'm not sure how that could even happen, a signal maybe ?</p>



<a name="178206811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178206811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178206811">(Oct 15 2019 at 15:55)</a>:</h4>
<p>But I don't think <code>std::thread</code>s catch any signals by default</p>



<a name="178207116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207116">(Oct 15 2019 at 15:58)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust-memory-model/issues/46" target="_blank" title="https://github.com/rust-lang/rust-memory-model/issues/46">https://github.com/rust-lang/rust-memory-model/issues/46</a></p>



<a name="178207257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207257">(Oct 15 2019 at 16:00)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> The difference between debug and release is probably because the nounwind marking on the FFI sleep call is wrong.</p>



<a name="178207336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207336">(Oct 15 2019 at 16:00)</a>:</h4>
<p>I don't think we misoptimize this case due to <code>nounwind</code>, but I can check that</p>



<a name="178207363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207363">(Oct 15 2019 at 16:00)</a>:</h4>
<p>(the only known misoptimization requires <code>noreturn</code> + <code>nounwind</code>)</p>



<a name="178207447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207447">(Oct 15 2019 at 16:02)</a>:</h4>
<p>If LLVM can see that there is no way for the unwind path to be reached then it will simply eliminate the unwind path.</p>



<a name="178207576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207576">(Oct 15 2019 at 16:03)</a>:</h4>
<p>Unwinding is still happening, it's just that the destructor isn't getting called because LLVM "knows" that it is unreachable.</p>



<a name="178207708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207708">(Oct 15 2019 at 16:04)</a>:</h4>
<p>One possible fix is to open up "man 7 pthreads" and add <code>#[unwind]</code> to all functions listed as cancellation points.</p>



<a name="178207728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207728">(Oct 15 2019 at 16:04)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> but the issue is that in debug builds destructors don't run, but they do run on release</p>



<a name="178207765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207765">(Oct 15 2019 at 16:04)</a>:</h4>
<p>that's the opposite of what I would expect if your hypothesis was true (LLVM optimizing debug builds, but not release builds)</p>



<a name="178207902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207902">(Oct 15 2019 at 16:06)</a>:</h4>
<p>In your second example you have a race. Add handle.join() at the end.</p>



<a name="178207910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178207910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178207910">(Oct 15 2019 at 16:06)</a>:</h4>
<p>The threads are overlapping</p>



<a name="178208216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178208216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178208216">(Oct 15 2019 at 16:09)</a>:</h4>
<p>Ah, I see what you mean now</p>



<a name="178208415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178208415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178208415">(Oct 15 2019 at 16:11)</a>:</h4>
<p>Weird</p>



<a name="178208854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178208854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178208854">(Oct 15 2019 at 16:15)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> so the race is part of the problem</p>



<a name="178208904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178208904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178208904">(Oct 15 2019 at 16:16)</a>:</h4>
<p>without <code>.join()</code>, the thread gets dettached</p>



<a name="178208923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178208923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178208923">(Oct 15 2019 at 16:16)</a>:</h4>
<p>but <code>pthread_cancel</code> was already called</p>



<a name="178208957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178208957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178208957">(Oct 15 2019 at 16:16)</a>:</h4>
<p>so even if unwinding starts happening, it can happen that <code>main</code> exits before that</p>



<a name="178208982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178208982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178208982">(Oct 15 2019 at 16:16)</a>:</h4>
<p>If you look up, it's aborting with an error</p>



<a name="178208990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178208990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178208990">(Oct 15 2019 at 16:16)</a>:</h4>
<p>FATAL: exception not rethrown</p>



<a name="178209012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209012">(Oct 15 2019 at 16:17)</a>:</h4>
<p>In the other case I mean</p>



<a name="178209015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209015">(Oct 15 2019 at 16:17)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=release&amp;edition=2018&amp;gist=fafb18f0e64c08faae4d602cbd120de1" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=release&amp;edition=2018&amp;gist=fafb18f0e64c08faae4d602cbd120de1">https://play.rust-lang.org/?version=nightly&amp;mode=release&amp;edition=2018&amp;gist=fafb18f0e64c08faae4d602cbd120de1</a></p>



<a name="178209057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209057">(Oct 15 2019 at 16:17)</a>:</h4>
<p>In that case, without <code>.join()</code>, the second thread has already been cancelled before main tries to exit, but it maybe gets dettached before the unwind is raised there</p>



<a name="178209064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209064">(Oct 15 2019 at 16:17)</a>:</h4>
<p>Oh that's just main exiting before the thread gets to handle the exception</p>



<a name="178209072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209072">(Oct 15 2019 at 16:17)</a>:</h4>
<p>yes</p>



<a name="178209162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209162">(Oct 15 2019 at 16:18)</a>:</h4>
<p>So this is all a false alert, unwind is working fine.</p>



<a name="178209170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209170">(Oct 15 2019 at 16:18)</a>:</h4>
<p>yes</p>



<a name="178209184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209184">(Oct 15 2019 at 16:18)</a>:</h4>
<p>well, "fine"</p>



<a name="178209201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209201">(Oct 15 2019 at 16:18)</a>:</h4>
<p>it is still unsound, but it is working reliably</p>



<a name="178209209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209209">(Oct 15 2019 at 16:18)</a>:</h4>
<p>Well apart from FATAL: exception not rethrown, but that's because it's crashing in the <code>catch_unwind</code> at the root of the thread</p>



<a name="178209256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209256">(Oct 15 2019 at 16:19)</a>:</h4>
<p>The unwind exception thrown by pthread_cancel is not meant to be caught</p>



<a name="178209269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209269">(Oct 15 2019 at 16:19)</a>:</h4>
<p>Yes, the problem is that <code>catch_unwind</code> probably doesn't know how to handle foreign exceptions</p>



<a name="178209276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209276">(Oct 15 2019 at 16:19)</a>:</h4>
<p>or the force exception</p>



<a name="178209279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209279">(Oct 15 2019 at 16:19)</a>:</h4>
<p>Maybe we should fix <code>catch_unwind</code> to ignore any non-Rust exceptions</p>



<a name="178209298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209298">(Oct 15 2019 at 16:19)</a>:</h4>
<p>that's what C++ does</p>



<a name="178209355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209355">(Oct 15 2019 at 16:20)</a>:</h4>
<p>well, C++ allows you to catch them in <code>catch(...)</code></p>



<a name="178209367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209367">(Oct 15 2019 at 16:20)</a>:</h4>
<p>but not in any other context</p>



<a name="178209396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209396">(Oct 15 2019 at 16:20)</a>:</h4>
<p>so if the error is "exception not rethrown", this must be a "force unwind"</p>



<a name="178209406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209406">(Oct 15 2019 at 16:20)</a>:</h4>
<p>and the Itanium ABI says that those must always be rethrown</p>



<a name="178209552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209552">(Oct 15 2019 at 16:22)</a>:</h4>
<p>_Unwind_ForcedUnwind</p>



<a name="178209671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178209671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178209671">(Oct 15 2019 at 16:23)</a>:</h4>
<p><a href="https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html#base-framework" target="_blank" title="https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html#base-framework">https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html#base-framework</a></p>
<blockquote>
<p>"forced" unwinding (such as caused by longjmp or thread termination).</p>
<p>During "forced unwinding", on the other hand, an external agent is driving the unwinding. For instance, this can be the longjmp routine. This external agent, not each personality routine, knows when to stop unwinding. The fact that a personality routine is not given a choice about whether unwinding will proceed is indicated by the _UA_FORCE_UNWIND flag.</p>
</blockquote>



<a name="178210209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178210209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178210209">(Oct 15 2019 at 16:28)</a>:</h4>
<p>IMO catch_unwind should only catch native rust exceptions. If you want to catch foreign exceptions, write a wrapper in C or C++.</p>



<a name="178210302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178210302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178210302">(Oct 15 2019 at 16:29)</a>:</h4>
<p>but this is not a foreign exception</p>



<a name="178210310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178210310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178210310">(Oct 15 2019 at 16:29)</a>:</h4>
<p>this is a ForceUnwind</p>



<a name="178210440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178210440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178210440">(Oct 15 2019 at 16:31)</a>:</h4>
<p>The ABI allows catching foreign exceptions and interrupting unwinding. What it doesn't allow is catching ForceUnwinds and interrupting unwinding (you can pause it, do something, but must rethrow the ForceUnwind afterwards).</p>



<a name="178210488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178210488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178210488">(Oct 15 2019 at 16:31)</a>:</h4>
<p>That doesn't mean that <code>catch_unwind</code> should catch foreign exceptions</p>



<a name="178210580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178210580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178210580">(Oct 15 2019 at 16:32)</a>:</h4>
<p>But even if it doesn't, we probably want to do so on the thread boundary anyways, and <code>abort</code></p>



<a name="178210634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178210634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178210634">(Oct 15 2019 at 16:33)</a>:</h4>
<p><del>or something like that</del> abort sounds good</p>



<a name="178210993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178210993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178210993">(Oct 15 2019 at 16:37)</a>:</h4>
<p>Otherwise the unwind will just terminate the process anyways IIUC</p>



<a name="178211074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178211074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178211074">(Oct 15 2019 at 16:38)</a>:</h4>
<p>Or how is unwinding propagated across a thread boundary ?</p>



<a name="178211253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178211253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178211253">(Oct 15 2019 at 16:40)</a>:</h4>
<p>Ah! This particular unwinding is allowed to reach the thread boundary, and that will cancel the thread</p>



<a name="178251753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178251753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> comex <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178251753">(Oct 16 2019 at 01:48)</a>:</h4>
<p>what happens with -C panic=abort?</p>



<a name="178310955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178310955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178310955">(Oct 16 2019 at 17:37)</a>:</h4>
<blockquote>
<p><a href="https://github.com/rust-lang/rust-memory-model/issues/46" target="_blank" title="https://github.com/rust-lang/rust-memory-model/issues/46">https://github.com/rust-lang/rust-memory-model/issues/46</a></p>
</blockquote>
<p>moved that to the UCG repo: <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/211" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/211">https://github.com/rust-lang/unsafe-code-guidelines/issues/211</a></p>



<a name="178311007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178311007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178311007">(Oct 16 2019 at 17:38)</a>:</h4>
<p>(we don't already have an issue covering that, do we?)</p>



<a name="178311030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178311030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178311030">(Oct 16 2019 at 17:38)</a>:</h4>
<p>but we dont have a fitting <code>A-*</code> I think... hm</p>



<a name="178311041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178311041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178311041">(Oct 16 2019 at 17:38)</a>:</h4>
<p><code>A-unwind</code>? <code>A-drop</code>?</p>



<a name="178361660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178361660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178361660">(Oct 17 2019 at 08:47)</a>:</h4>
<p><span class="user-mention" data-user-id="198590">@comex</span> AFAICT, with <code>-C panic=abort</code>, the stack frame unwinds</p>



<a name="178361676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178361676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178361676">(Oct 17 2019 at 08:47)</a>:</h4>
<p>Otherwise you can't cancel threads in C without <code>-fexceptions</code></p>



<a name="178361748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel%20looks%20unsound/near/178361748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/pthread_cancel.20looks.20unsound.html#178361748">(Oct 17 2019 at 08:48)</a>:</h4>
<p>Destructors aren't necessarily run when that happens though</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>